package kr.or.kosta.otr.service.userservice;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import kr.or.kosta.otr.persistence.admin.AdminDao;
import kr.or.kosta.otr.persistence.company.CompanyDao;
import kr.or.kosta.otr.persistence.companyreview.CompanyReviewDao;
import kr.or.kosta.otr.persistence.companyreviewverify.CompanyReviewVerifyDao;
import kr.or.kosta.otr.persistence.interestcompany.InterestCompanyDao;
import kr.or.kosta.otr.persistence.interestreview.InterestReviewDao;
import kr.or.kosta.otr.persistence.mentor.MentorDao;
import kr.or.kosta.otr.persistence.message.MessageDao;
import kr.or.kosta.otr.persistence.messagetype.MessageTypeDao;
import kr.or.kosta.otr.persistence.report.ReportDao;
import kr.or.kosta.otr.persistence.score.ScoreDao;
import kr.or.kosta.otr.persistence.user.UserDao;
import kr.or.kosta.otr.persistence.usertype.UserTypeDao;
import kr.or.kosta.otr.utill.BoardListVO;
import kr.or.kosta.otr.utill.MessageListVO;
import kr.or.kosta.otr.utill.PagingBean;
import kr.or.kosta.otr.utill.ReportListVO;
import kr.or.kosta.otr.vo.AdminVO;
import kr.or.kosta.otr.vo.BoardVO;
import kr.or.kosta.otr.vo.CompanyReviewVO;
import kr.or.kosta.otr.vo.CompanyVO;
import kr.or.kosta.otr.vo.MentorVO;
import kr.or.kosta.otr.vo.MessageTypeVO;
import kr.or.kosta.otr.vo.MessageVO;
import kr.or.kosta.otr.vo.ReportVO;
import kr.or.kosta.otr.vo.TrueOrFalseVO;
import kr.or.kosta.otr.vo.UserTypeVO;
import kr.or.kosta.otr.vo.UserVO;

import org.springframework.stereotype.Service;

@Service("UserService")
public class UserServiceImpl implements UserService{
	
	@Resource(name="UserDao")
	UserDao userDao;
		
	@Resource(name="AdminDao")
	AdminDao adminDao;
	
	@Resource(name="UserTypeDao")
	UserTypeDao userTypeDao;
	
	@Resource(name="MessageDao")
	MessageDao messageDao;
	
	@Resource(name="ReportDao")
	ReportDao reportDao;
	
	@Resource(name="CompanyReviewDao")
	CompanyReviewDao companyReviewDao;
	
	@Resource(name="CompanyReviewVerifyDao")
	CompanyReviewVerifyDao companyReviewVerifyDao;
	
	@Resource(name="ScoreDao")
	ScoreDao scoreDao;
	
	@Resource(name="MessageTypeDao")
	MessageTypeDao messageTypeDao;
	
	@Resource(name="MentorDao")
	MentorDao mentorDao;
	
	@Resource(name="CompanyDao")
	CompanyDao companyDao;
	
	@Resource(name="InterestReviewDao")
	InterestReviewDao interestReviewDao;
	
	@Resource(name="InterestCompanyDao")
	InterestCompanyDao interestCompanyDao;
	
	@Override
	public void register(UserVO vo) throws SQLException {
		userDao.addUser(vo);
	}

	@Override
	public UserVO userlogin(HashMap<String, String> map) throws SQLException {
		return userDao.getOneUser(map);
	}
	
	@Override
	public AdminVO adminlogin(HashMap<String, String> map) throws SQLException {
		return adminDao.getOneAdmin(map);
	}
	
	@Override
	public UserVO findId(String email) throws SQLException {
		 UserVO vo = userDao.getOneUserIdByEmail(email);
		 return vo;
	}

	@Override
	public UserVO findPassword(String id) throws SQLException {
		return userDao.getOneSecretByUserId(id);
	}

	@Override
	public AdminVO getAdmin() throws SQLException {
		// TODO Auto-generated method stub
		return adminDao.getAdmin();
	}
	
	@Override
	public UserTypeVO getUserType(int userTypeId) throws SQLException {
		// TODO Auto-generated method stub
		return userTypeDao.getUserType(userTypeId);
	}
	
	@Override
	public boolean isExist(String userId) throws SQLException {
		
		return userDao.isExist(userId);
	}

	@Override
	public int getMessageCount(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return messageDao.getMessageCount(userId);
	}

	@Override
	public int getReportCount(String adminId) throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.getReportCount(adminId);
	}

	@Override
	public ArrayList<MessageVO> getAllMessage(String userId)
			throws SQLException {
		// TODO Auto-generated method stub
		return messageDao.getAllMessage(userId);
	}

	@Override
	public ArrayList<MessageVO> getAllSendMessage(String userId)
			throws SQLException {
		// TODO Auto-generated method stub
		return messageDao.getAllSendMessage(userId);
	}

	@Override
	public ArrayList<ReportVO> getAllUserSendMessage(String userId)
			throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.getAllSendReprot(userId);
	}

	@Override
	public ArrayList<ReportVO> getAllAdminMessage(String adminId)
			throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.getAllReprot(adminId);
	}

	@Override
	public ArrayList<CompanyReviewVO> getAllCompanyReviewByUserId(String userId)
			throws SQLException {
		
		return companyReviewDao.getAllCompanyReview();
	}

	@Override
	public ArrayList<TrueOrFalseVO> getCompanyReviewVerifyByUserId(String userId)
			throws SQLException {
		
		return companyReviewVerifyDao.getCompanyReviewVerifyByUserId(userId);
	}

	@Override
	public float getCompanyScoreTotal(int companyId) throws SQLException {
		
		return scoreDao.getCompanyScoreTotal(companyId);
	}

	@Override
	public void updateTotalScore(int scoreId) throws SQLException {
		scoreDao.updateTotalScore(scoreId);
		
	}

	@Override
	public void deleteMessage(int messageId) throws SQLException {
		// TODO Auto-generated method stub
		messageDao.deleteMessage(messageId);
	}

	@Override
	public void checkMessage(HashMap<String, Object> map) throws SQLException {
		// TODO Auto-generated method stub
		messageDao.checkMessage(map);
	}

	@Override
	public void checkReport(HashMap<String, Object> map) throws SQLException {
		// TODO Auto-generated method stub
		reportDao.checkReport(map);
	}

	@Override
	public void deleteReport(int reportId) throws SQLException {
		// TODO Auto-generated method stub
		reportDao.deleteReport(reportId);
	}

	@Override
	public int writeReport(ReportVO vo) throws SQLException {
		
		return reportDao.writeReport(vo);
	}

	@Override
	public ArrayList<MessageTypeVO> getAllMessageType() throws SQLException {
		
		return messageTypeDao.getAllMessageType();
	}

	@Override
	public MessageTypeVO getMessageType(HashMap<String, Object> map) throws SQLException {
		
		return messageTypeDao.getMessageType(map);
	}

	@Override
	public void writeMessage(MessageVO vo) throws SQLException {
		messageDao.writeMessage(vo);
		
	}

	@Override
	public void updatePointMinus(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		userDao.updatePointMinus(map);
	}

	@Override
	public MessageVO getOneMessage(int messageId) throws SQLException {
		// TODO Auto-generated method stub
		return messageDao.getOneMessage(messageId);
	}

	@Override
	public void deleteUser(String userId) throws SQLException {
		userDao.deleteUser(userId);
		
	}

	@Override
	public void updateUser(UserVO vo) throws SQLException {
		userDao.updateUser(vo);
		
	}

	@Override
	public UserVO getOneUser(HashMap<String, String> map) throws SQLException {
		
		return userDao.getOneUser(map);
	}

	@Override
	public ArrayList<MentorVO> getAllMentor(HashMap<String, Object> map)
			throws SQLException {
		
		return mentorDao.getAllMentor(map);
	}

	@Override
	public CompanyVO getOneCompanyByName(String companyName)
			throws SQLException {
		
		return companyDao.getOneCompanyByName(companyName);
	}

	@Override
	public int myCompanyReviewVerifyByUserId(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return companyReviewVerifyDao.myCompanyReviewVerifyByUserId(userId);
	}

	@Override
	public int myInterestReview(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return interestReviewDao.myInterestReview(userId);
	}

	@Override
	public int myInterestCompany(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return interestCompanyDao.myInterestCompany(userId);
	}

	@Override
	public ArrayList<CompanyVO> getCompanyInfo(HashMap<String, Object> map)
			throws SQLException {
		
		return companyDao.getCompanyInfo(map);
	}

	@Override
	public void deleteCompanyReview(int company_review_id) throws SQLException {
		// TODO Auto-generated method stub
		companyReviewDao.deleteCompanyReview(company_review_id);
	}

	@Override
	public MessageListVO getAllMessagePage(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		int pn=1;
		String pageNo = (String) map.get("value");
		if(pageNo!=null){
			pn=Integer.parseInt(pageNo);
		}
		map.put("value", pn);
		ArrayList<MessageVO> list=messageDao.getAllMessagePage(map);
		String userId = (String) map.get("userId");
		int totalContents=messageDao.getAllMessageTotal(userId);
		PagingBean pb=new PagingBean(totalContents, pn);

		return new MessageListVO(list, pb);
	}

	@Override
	public ReportListVO getAllReportPage(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		int pn=1;
		String pageNo = (String) map.get("value");
		if(pageNo!=null){
			pn=Integer.parseInt(pageNo);
		}
		map.put("value", pn);
		ArrayList<ReportVO> list=reportDao.getAllReprotPage(map);
		String adminId = (String) map.get("adminId");
		int totalContents=reportDao.getAllReprotTotal(adminId);
		PagingBean pb=new PagingBean(totalContents, pn);

		return new ReportListVO(list, pb);
	}

	@Override
	public ArrayList<TrueOrFalseVO> getCompanyReviewVerifyByUserIdPage(
			HashMap<String, Object> map) throws SQLException {
		// TODO Auto-generated method stub
		int pn=1;
		String pageNo = (String) map.get("value");
		if(pageNo!=null){
			pn=Integer.parseInt(pageNo);
		}
		map.put("value", pn);
		ArrayList<TrueOrFalseVO> list= companyReviewVerifyDao.getCompanyReviewVerifyByUserIdPage(map);
		
		return list;
	}

	@Override
	public int getCompanyReviewVerifyByUserIdTotal(String userId)
			throws SQLException {
		// TODO Auto-generated method stub
		return companyReviewVerifyDao.getCompanyReviewVerifyByUserIdTotal(userId);
	}

	@Override
	public void updatePointPlus(HashMap<String, Object> map)
			throws SQLException {
		userDao.updatePointPlus(map);
		
	}
	@Override
	public int getUserPoint(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return userDao.getUserPoint(userId);
	}
}
